<script setup lang="ts" name="LoveTalk">
import axios from 'axios'
import {nanoid} from "nanoid";
import {useLoveTalkStore} from "@/stores/LoveTalk";
import {storeToRefs} from "pinia";

let loveTalkStore = useLoveTalkStore()
let {list} = storeToRefs(loveTalkStore)
console.log('list1', loveTalkStore.list)
console.log('list2', list)

loveTalkStore.$subscribe((mutation, state) => {
  console.log("loveTalkStore里的数据改变了", mutation, state)
  localStorage.setItem('talkList', JSON.stringify(state.list))
})

async function getLoveTalk() {
  await loveTalkStore.getLoveTalk()
}

</script>

<template>
<div>
  <button @click="getLoveTalk">获取一条</button>
  <ul >
    <li v-for="item in list" :key="item.id">{{item.title}}</li>
  </ul>
</div>
</template>
<style scoped>

</style>